// 153.寻找旋转排序数组中的最小值
package LeetcodeHot100;

public class Solution153 {
    public int findMin(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = (left + right) >> 1;
            if (nums[mid] >= nums[left]) {
                if (mid + 1 < nums.length && nums[mid] > nums[mid + 1])
                    return nums[mid + 1];
                else
                    left = mid + 1;
            } else {
                if (mid - 1 >= 0 && nums[mid] < nums[mid - 1])
                    return nums[mid];
                else
                    right = mid - 1;
            }
        }
        return nums[0];
    }
}
